package com.group9.handinhand.controller.form;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.group9.handinhand.service.so.CommunityMemberSO;
import com.group9.handinhand.service.so.RequestPostSO;
import com.group9.handinhand.service.so.RequestResponseSO;
import com.group9.handinhand.service.so.RequestSO;
import com.group9.handinhand.service.so.UserTagSO;

public class RequestViewForm {
	
	RequestSO request;
	RequestSO moderatedRequest;
	CommunityMemberSO communityMember;
	String post;
	int goodsAmount;
	int servicesAmount;
	int userContribution;
	ArrayList<Object> wallElements = new ArrayList<Object>();
	List<UserTagSO> userTags;
	ArrayList<Object> requestList;
	/**
	 * A set method.
	 * Sets elements on the request wall to the request.
	 */
	public void setWallElementsFromRequest(){
		wallElements.addAll(request.getPosts());
		Collections.sort(wallElements, new Comparator<Object>() {
			
			public int compare(Object o1, Object o2) {
				Date o1createDate = ((RequestPostSO)o1).getCreateDate();
						
				Date o2createDate = ((RequestPostSO)o2).getCreateDate();
				if (o1createDate == null || o2createDate == null)
					return 0;
				return o2createDate.compareTo(o1createDate);
			}
		});

	}
	
	public RequestSO getModeratedRequest() {
		return moderatedRequest;
	}

	public void setModeratedRequest(RequestSO moderatedRequest) {
		this.moderatedRequest = moderatedRequest;
	}

	public ArrayList<Object> getWallElements() {
		return wallElements;
	}

	public void setWallElements(ArrayList<Object> wallElements) {
		this.wallElements = wallElements;
	}
	
	public CommunityMemberSO getCommunityMember() {
		return communityMember;
	}

	public void setCommunityMember(CommunityMemberSO communityMember) {
		this.communityMember = communityMember;
	}

	public String getPost() {
		return post;
	}

	public void setPost(String post) {
		this.post = post;
	}

	public RequestSO getRequest() {
		return request;
	}

	public void setRequest(RequestSO request) {
		this.request = request;
	}
	
	public int getGoodsAmount() {
		return goodsAmount;
	}

	public void setGoodsAmount(int goodsAmount) {
		this.goodsAmount = goodsAmount;
	}

	public int getServicesAmount() {
		return servicesAmount;
	}

	public void setServicesAmount(int servicesAmount) {
		this.servicesAmount = servicesAmount;
	}

	public int getUserContribution() {
		return userContribution;
	}

	public void setUserContribution(int userContribution) {
		this.userContribution = userContribution;
	}
	/**
	 * A set method.
	 * Sets the response of the user for request.
	 * @param list
	 */
	public void setUserContributionFromList(ArrayList<RequestResponseSO> list){
		userContribution = 0;
		for (RequestResponseSO requestResponseSO : list) {
			userContribution += requestResponseSO.getRespondAmount();
		}
	}

	public List<UserTagSO> getUserTags() {
		return userTags;
	}

	public void setUserTags(List<UserTagSO> userTags) {
		this.userTags = userTags;
	}



	public ArrayList<Object> getRequestList() {
		return requestList;
	}

	public void setRequestList(ArrayList<Object> requestList) {
		this.requestList = requestList;
	}

	@Override
	public String toString() {
		return "RequestViewForm [request=" + request + ", post=" + post
				+ ", goodsAmount=" + goodsAmount + ", servicesAmount="
				+ servicesAmount + ", userContribution=" + userContribution
				+ ", wallElements=" + wallElements + "]";
	}

}
